from django.db.models import CharField,DateTimeField,IntegerField,DateField,DecimalField,TextField,ForeignKey,BooleanField,DO_NOTHING,PROTECT
from apps.vadmin.op_drf.models import CoreModel


class Licenses(CoreModel):
    name = CharField(max_length=256,null=False,verbose_name="许可证名称")
    serial = CharField(max_length=256,null=True,verbose_name="序列号")
    category = ForeignKey(to="assets.Categories",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="分类Id")
    deleted_datetime = DateTimeField(null=True,verbose_name="删除时间")
    purchase_date = DateField(null=True,verbose_name="购买日期")
    purchase_cost = DecimalField(null=True,max_digits=20,decimal_places=2,verbose_name="采购价格")
    seats = IntegerField(null=True,default=1,verbose_name="授权使用数量")
    checkout_seats = IntegerField(null=True,default=0,verbose_name="借出数量")
    notes = TextField(null=True,verbose_name="备注")
    depreciation = ForeignKey(to="assets.Depreciations",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="折旧Id")
    license_name = CharField(null=True,max_length=128,verbose_name="授权人名称")
    license_email = CharField(null=True,max_length=128,verbose_name="授权人email")
    depreciate = BooleanField(null=True,default=0,verbose_name="")
    expiration_date = DateField(null=True,verbose_name="到期日期")
    termination_date = DateField(null=True,verbose_name="终止日期")
    order_number = CharField(max_length=256,null=True,verbose_name="订单编号")
    purchase_order = CharField(null=True,max_length=128,verbose_name="采购订单号")
    maintained = BooleanField(null=True,verbose_name="保持")
    reassignable = BooleanField(null=False,default=1,verbose_name="可重新授权")
    supplier = ForeignKey(to="assets.Suppliers",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="供应商")
    manufacturer = ForeignKey(to="assets.Manufacturers",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="制造商")

    class Meta:
        verbose_name = '软件许可证'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"{self.name}"
